home *** CD-ROM | disk | FTP | other *** search
/ Mac Cube 4: Multimedia Applications / MacCube Volume 4: Multimedia Applications.iso / Graphics / NIH Image Folder / Macros / Gel Plotting Macros < prev    next >
Text File  |  1993-07-29  |  5KB  |  184 lines

  1. var  {Global variables}
  2.   RoiLeft,RoiTop,RoiWidth,RoiHeight,PlotColor:integer;
  3.   GelWidth,GelHeight,MaxPlotWindowHeight,NeededSize:integer;
  4.   GelWindow,PlotWindow,PlotLeft,PlotTop,PlotWidth,PlotHeight:integer;
  5.   hMargin,vMargin,nLanes,SavePlotTop,PlotWindowSize:integer;
  6.   LeftMargin,TopMargin,RightMargin,BottomMargin:integer;
  7.   FirstBackgroundPlot:boolean;
  8.  
  9. macro 'Setup to Plot Gel [Z]';
  10. {This macro, along with the Plot Lane macro, is used to generate profile}
  11. {plots of the lanes in a one dimensional electoproretic gel.}
  12. var
  13.   nPixels,mean,mode,min,max:real;
  14.   PlotWinHeight:integer;
  15. begin
  16.   RequiresVersion(1.50);
  17.   PlotHeight:=175;
  18.   PlotWidth:=500;
  19.   MaxPlotWindowHeight:=720;
  20.   GetRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight);
  21.   if RoiWidth=0 then begin
  22.     PutMessage('The Setup macro expects the Gel to be displayed and the first lane outlined.');
  23.     exit;
  24.   end;
  25.   if PlotWidth<RoiWidth then PlotWidth:=RoiWidth;
  26.   if PlotWidth>(2*RoiWidth) then PlotWidth:=2*RoiWidth;
  27.   if RoiHeight>RoiWidth then begin
  28.     PutMessage('Lanes must be horizontal.');
  29.     exit;
  30.   end;
  31.   if nPics<>1 then begin
  32.     PutMessage('The window containing the gel should be the only image window open.');
  33.     exit;
  34.   end;
  35.   nLanes:=GetNumber('Number of lanes?',1);
  36.   GetPicSize(GelWidth,GelHeight);
  37.   MakeRoi(RoiLeft,RoiTop,RoiWidth,GelHeight-RoiTop);
  38.   Measure;
  39.   GetResults(nPixels,mean,mode,min,max);
  40.   hMargin:=5;
  41.   vMargin:=5;
  42.   if Calibrated
  43.     then LeftMargin:=35
  44.     else LeftMargin:=25;
  45.   TopMargin:=10;
  46.   RightMargin:=20;
  47.   BottomMargin:=20;
  48.   PlotLeft:=hMargin-LeftMargin;
  49.   PlotTop:=vMargin-TopMargin;
  50.   SavePlotTop:=PlotTop;
  51.   PlotWinHeight:=nLanes*PlotHeight+2*vMargin;
  52.   if PlotWinHeight>MaxPlotWindowHeight then begin
  53.     PlotWinHeight:=MaxPlotWindowHeight;
  54.     PlotHeight:=(PlotWinHeight-2*vMargin)/nLanes;
  55.   end;
  56.   PlotWindowSize:=(PlotWidth+2*hMargin)*PlotWinHeight;
  57.   if PlotWindowSize>UndoBufferSize then begin
  58.     NeededSize:=(PlotWindowSize+0.05*PlotWindowSize) div 1024;
  59.     PutMessage('Use Preferences(Options Menu) to increase the Undo buffer size to at least ',NeededSize:1,'K.');
  60.     KillRoi;
  61.     exit;
  62.   end;
  63.   SetNewSize(PlotWidth+2*hMargin,PlotWinHeight);
  64.   SetForegroundColor(255);
  65.   SetBackgroundColor(0);
  66.   MakeNewWindow('Plots');
  67.   SetPlotSize(PlotWidth,PlotHeight);
  68.   min:=min-1;
  69.   if min<0 then min:=0;
  70.   max:=max+5;
  71.   if max>255 then max:=255;
  72.   SetPlotScale(cValue(min),cValue(max));
  73.   SetPlotLabels(false);
  74.   GelWindow:=1;
  75.   PlotWindow:=2;
  76.   SelectPic(GelWindow);
  77.   MakeRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight);
  78.   FirstBackgroundPlot:=true;
  79.   PlotColor:=1;
  80.   ResetCounter;
  81.   MeasureArea(true);
  82.   MeasureDensity(false);
  83.   WandAutoMeasure(true);
  84.   AdjustAreas(true);
  85.   LabelParticles(false);
  86.   IncludeInteriorHoles(true);
  87.   SetFontSize(9);
  88.   SetText('Centered');
  89.   SetLineWidth(1);
  90. end;
  91.  
  92.  
  93. macro 'Plot Lane [P]';
  94. var
  95.   left,top,width,height:integer;
  96.   GelNotCalibrated:boolean;
  97. begin
  98.   if (GelWidth=0) or (nPics=1) then begin
  99.     PutMessage
  100.       ('Before using the Plot Lane macro you must first use the Setup macro.');
  101.     Exit;
  102.   end;
  103.   GelNotCalibrated:=not Calibrated;
  104.   GetRoi(left,top,width,height);
  105.   MakeRoi(RoiLeft,top,RoiWidth,RoiHeight);
  106.   SetOption;
  107.   ColumnAveragePlot;
  108.   Copy;
  109.   SelectPic(PlotWindow);
  110.   MakeRoi(PlotLeft,PlotTop,PlotWidth+LeftMargin+RightMargin,
  111.           PlotHeight+TopMargin+BottomMargin);
  112.   Paste;
  113.   DoOr;
  114.   if GelNotCalibrated and (PlotTop=SavePlotTop) then begin
  115.     SetText('Left Justified; With Background');
  116.     MoveTo(PlotLeft+LeftMargin+6,PlotTop+TopMargin+1);
  117.     SetFontSize(12);
  118.     Write('Uncalibrated');
  119.     SetFontSize(9);
  120.     SetText('Centered; No Background');
  121.   end;
  122.   PlotTop:=PlotTop+PlotHeight-1;
  123.   SelectPic(GelWindow);
  124. end;
  125.  
  126.  
  127. macro 'Plot Background Lane [B]';
  128. {Plot all lanes before plotting backgrounds. Unlike the lane plotting macro,}
  129. {you are allowed to change the height of the selection.}
  130. var
  131.   left,top,width,height:integer;
  132. begin
  133.   if (GelWidth=0) or (nPics=1) then begin
  134.     PutMessage('Use Setup first.');
  135.     Exit;
  136.   end;
  137.   GetRoi(left,top,width,height);
  138.   MakeRoi(RoiLeft,top,RoiWidth,height);
  139.   ColumnAveragePlot;
  140.   Copy;
  141.   SelectPic(PlotWindow);
  142.   if FirstBackgroundPlot then begin
  143.     FirstBackgroundPlot:=false;
  144.     PlotTop:=SavePlotTop;
  145.   end;
  146.   MakeRoi(PlotLeft,PlotTop,PlotWidth+LeftMargin+RightMargin,
  147.           PlotHeight+TopMargin+BottomMargin);
  148.   Paste;
  149.   DoOr;
  150.   PlotTop:=PlotTop+PlotHeight-1;
  151.   SelectPic(GelWindow);
  152. end;
  153.  
  154.  
  155. macro 'Plot Overlayed [O]';
  156. var
  157.   left,top,width,height:integer;
  158. begin
  159.   if (GelWidth=0) or (nPics=1) then begin
  160.     PutMessage('Use Setup first.');
  161.     Exit;
  162.   end;
  163.   if PlotColor=1 then SetPalette('256 Color Spectrum');
  164.   GetRoi(left,top,width,height);
  165.   MakeRoi(RoiLeft,top,RoiWidth,height);
  166.   ColumnAveragePlot;
  167.   Copy;
  168.   SelectPic(PlotWindow);
  169.   if PlotColor=1 then SetPalette('256 Color Spectrum');
  170.   SetForegroundColor(PlotColor);
  171.   PlotTop:=PlotTop-PlotHeight+1;
  172.   if PlotTop<SavePlotTop then PlotTop:=SavePlotTop;
  173.   MakeRoi(PlotLeft,PlotTop,PlotWidth+LeftMargin+RightMargin,
  174.           PlotHeight+TopMargin+BottomMargin);
  175.   Paste;
  176.   DoOr;
  177.   PlotTop:=PlotTop+PlotHeight-1;
  178.   SelectPic(GelWindow);
  179.   PlotColor:=(PlotColor+74) mod 254;
  180. end;
  181.  
  182.  
  183.  
  184.